package com.enki.cigarettes.repository;

import com.enki.cigarettes.entity.BalanceHistoryT;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;


/**
 * @author WCS.Wang
 * @version V1.0
 * @Package com.enki.cigarettes.repository
 * @Name e-cigarettes-shop-api-module
 * @Description: TODO (用一句话描述该文件做什么)
 * @date 2019-08-08
 */
public interface BalanceHistoryTRepository extends PagingAndSortingRepository<BalanceHistoryT, String> {

    // 根绝用户ID分页查询
    Page<BalanceHistoryT> findByUserTId(String userTId, Pageable pageable);

    // 根绝用户ID、余额状态分页查询
    Page<BalanceHistoryT> findByUserTIdAndBalanceStatus(String userTId, int balanceStatus, Pageable pageable);

    @Query("select sum(bh.subTotal) from BalanceHistoryT bh where bh.userTId=?1 and bh.balanceStatus=?2")
    List<Object> sumBalanceByUserId(String userTId, int balanceStatus);

}
